package com.mym.system;

import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Objects;
import java.util.Scanner;

/**
 * @author miao
 * @version 1.0
 * @date 2025/4/15 16:06
 * @description
 */
public class User {
    public static Scanner scanner = new Scanner(System.in);
    // 定义私有属性
    private String userName;
    private String passWord;
    private String otherName;
    private int age;

    public User() {
    }

    public User(String userName, String passWord, String otherName, int age) {
        this.userName = userName;
        this.passWord = passWord;
        this.otherName = otherName;
        this.age = age;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassWord() {
        return passWord;
    }

    public void setPassWord(String passWord) {
        this.passWord = passWord;
    }

    public String getOtherName() {
        return otherName;
    }

    public void setOtherName(String otherName) {
        this.otherName = otherName;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        User user = (User) o;
        return age == user.age && Objects.equals(userName, user.userName) && Objects.equals(passWord, user.passWord) && Objects.equals(otherName, user.otherName);
    }

    @Override
    public int hashCode() {
        return Objects.hash(userName, passWord, otherName, age);
    }

    @Override
    public String toString() {
        return "User{" +
                "userName='" + userName + '\'' +
                ", passWord='" + passWord + '\'' +
                ", otherName='" + otherName + '\'' +
                ", age=" + age +
                '}';
    }

    // 定义一个方法传入密码判断长度不小于6
    public String isPassWord() {
        Scanner scanner = new Scanner(System.in);
        while (true) {
            System.out.println("请输入密码");
            String passWord = scanner.nextLine();
            if (passWord.length() < 6) {
                System.out.println("密码长度不能小于6");
            } else {
                return passWord;
            }
        }
    }

    // 定义一个方法判断输入两次密码是否相同
    public String isPassWord2() {
        Scanner scanner = new Scanner(System.in);
        while (true) {
            String passWord = isPassWord();
            System.out.println("请再次输入密码");
            String passWord2 = scanner.nextLine();
            if (passWord.equals(passWord2)) {
                return passWord;
            } else {
                System.out.println("两次密码不一致");
            }
        }
    }

    // 定义一个方法用户名不能重复
    public void isUserNameAndPassWordAndAgeAndOtherName() {
        Scanner scanner = new Scanner(System.in);

        // 用户输入用户名
        System.out.println("请输入用户名");
        String scuser = scanner.nextLine();

        // 用户输入密码并确认
        String scpassWord = isPassWord2();

        // 用户输入其他信息
        System.out.println("请输入其他名称");
        String scotherName = scanner.nextLine();

        System.out.println("请输入年龄");
        int scage = scanner.nextInt();
        //年龄必须是0-100之间的数字
        while (scage < 0 || scage > 100) {
            System.out.println("年龄必须是0-100之间的数字");
            System.out.println("请重新输入年龄");
            scage = scanner.nextInt();
        }

        // 设置用户信息
        this.setUserName(scuser);
        this.setPassWord(scpassWord);
        this.setOtherName(scotherName);
        this.setAge(scage);

        //输出注册成功
        System.out.println("注册成功");
        //显示注册成功的时间
        LocalDate now = LocalDate.now();
        //将now转换为字符串
        String format = now.format(java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        System.out.println("注册成功时间：" + format);
    }

    //用户登录方法
    public void isLogin() {
        Scanner scanner = new Scanner(System.in);
        //确认用户输入的用户名和密码是否正确
        while (true) {
            System.out.println("请输入用户名");
            String scuser = scanner.nextLine();
            System.out.println("请输入密码");
            String scpassWord = scanner.nextLine();
            if (scuser.equals(this.getUserName()) && scpassWord.equals(this.getPassWord())) {
                System.out.println("登录成功");
                //输出用户名
                System.out.println("用户名：" + scuser);
                //调用登陆成功后的方法
                isLoginSuccess();
            }
            else {
                System.out.println("用户名或者密码输入错误");
            }
        }

    }
    //登陆成功后显示的界面
    public static final  ShangPing shangPing = new ShangPing();
    public void isLoginSuccess() {

        while (true) {
            System.out.println("**************电器商城******************");
            System.out.println("1.商品购买");
            System.out.println("2.我的购物车");
            System.out.println("3.个人信息");
            System.out.println("4.注销");
            System.out.println("**************电器商城******************");
            System.out.println("请输入您的选择");
            Scanner scanner = new Scanner(System.in);
            int num = scanner.nextInt();
            switch (num) {
                case 1:
                    shangPing.initGoodsInfo();
                    break;
                case 2:
                    break;
                case 3:
                    break;
                case 4:
                    break;
                default:
                    System.out.println("输入错误");
                    break;
            }
        }
    }


}
